/*
Copyright (c) 2008, Oleg S. Estekhin
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * Neither the name of the copyright holders nor the names of its
      contributors may be used to endorse or promote products derived from this
      software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package ebml.io;

import java.io.Closeable;
import java.io.IOException;

/** Represents an input source of bytes. */
public interface InputSource extends Closeable {

    /**
     * Reads up to <code>length</code> bytes of data from the input source into an array of bytes.
     *
     * @param buffer the buffer into which the data is read
     * @param offset the start offset in <code>buffer</code> at which the data is written
     * @param length the maximum number of bytes to read
     *
     * @return the actual number of bytes read, or <code>-1</code> if the end of the input source is reached
     *
     * @throws NullPointerException if <code>buffer</code> is <code>null</code>
     * @throws IndexOutOfBoundsException if <code>offset</code> is negative, <code>length</code> is negative, or
     * <code>length</code> is greater than <code>buffer.length - offset</code>
     * @throws IOException if an I/O error has occurred
     */
    int read(byte[] buffer, int offset, int length) throws IOException;

    /**
     * Skips up to <code>length</code> bytes in the input source.
     *
     * @param length the maximum number of bytes to skip
     *
     * @return the actual number of bytes skipped
     *
     * @throws IllegalArgumentException if <code>length</code> is negative
     * @throws IOException if an I/O error has occurred
     */
    long skip(long length) throws IOException;

    /**
     * Returns the current source position.
     *
     * @return the source position
     */
    long getPosition();

}
